[XEND] Refactoring device controllers to its own module so it can be used by both...
authorAlastair Tse <atse@xensource.com>
Thu, 5 Oct 2006 16:29:19 +0000 (17:29 +0100)
committerAlastair Tse <atse@xensource.com>
Thu, 5 Oct 2006 16:29:19 +0000 (17:29 +0100)
Signed-off-by: Alastair Tse <atse@xensource.com>
tools/python/xen/xend/XendDevices.py [new file with mode: 0644]

diff --git a/tools/python/xen/xend/XendDevices.py b/tools/python/xen/xend/XendDevices.py
new file mode 100644 (file)
index 0000000..4125cee
--- /dev/null
@@ -0,0 +1,68 @@
+#===========================================================================
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of version 2.1 of the GNU Lesser General Public
+# License as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#============================================================================
+# Copyright (C) 2006 XenSource Ltd
+#============================================================================
+
+#
+# A collection of DevControllers 
+#
+
+from xen.xend.server import blkif, netif, tpmif, pciif, iopif, irqif, usbif
+from xen.xend.server.BlktapController import BlktapController
+
+class XendDevices:
+    """ An ugly halfway point between the module local device name
+    to class map we used to have in XendDomainInfo and something
+    slightly more managable.
+
+    This class should contain all the functions that have to do
+    with managing devices in Xend. Right now it is only a factory
+    function.
+    """
+
+    controllers = {
+        'vbd': blkif.BlkifController,
+        'vif': netif.NetifController,
+        'vtpm': tpmif.TPMifController,
+        'pci': pciif.PciController,
+        'ioports': iopif.IOPortsController,
+        'irq': irqif.IRQController,
+        'usb': usbif.UsbifController,
+        'tap': BlktapController,
+    }
+
+    #@classmethod
+    def valid_devices(cls):
+        return cls.controllers.keys()
+    valid_devices = classmethod(valid_devices)
+
+    #@classmethod
+    def make_controller(cls, name, domain):
+        """Factory function to make device controllers per domain.
+
+        @param name: device class name in L{VALID_DEVICES}
+        @type name: String
+        @param domain: domain this controller is handling devices for.
+        @type domain: XendDomainInfo
+        @return: DevController of class 'name' or None
+        @rtype: subclass of DevController
+        """
+        if name in cls.controllers.keys():
+            cls.controllers[name].deviceClass = name
+            return cls.controllers[name](domain)
+        return None
+
+    make_controller = classmethod(make_controller)
+